<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/measure.css">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


	$(function() {

		//初始化页面配置
		initPage("产品测量");

		var app = new Vue({
			el: '#container',
			data: {
			},
			methods: {
				cancel: function() {
					window.location.href = "/wechat/order/index/id/{$product.product_id}";
				},
				save: function() {

					var measureData = {};

					measureData["data"] = {};

					var canSubmit = true;
					var msg = "";

					$(".edit-content .item").each(function(index) {

						var keyword = $(this).find("span").text();
						var value = $(this).find("input").val();
						var code = $(this).find("input").attr("keyword");

						if(isNullOrEmpty(value)) {
							msg = "请填写"+keyword;
							canSubmit = false;
							return false;
						}

						var data = {};

						data.keyword = keyword;
						data.code = code;
						data.value = value;

						measureData["data"][index] = data;

					});

					if(!canSubmit) {
						alert(msg);
						return false;
					}

					measureData["productId"] = "{$product.product_id}";

					localStorage.setItem("measureData", JSON.stringify(measureData));

					window.location.href = "/wechat/order/index/id/{$product.product_id}";

				}
			}
		})

		var measureData = window.localStorage.getItem("measureData");
		if(!isNullOrEmpty(measureData)) {
			var measureData = JSON.parse(measureData);
			if(measureData.productId == "{$product.product_id}") {
				for(var i=0; i<Object.keys(measureData.data).length; i++){
					$("input[keyword="+measureData.data[i].code+"]").val(measureData.data[i].value);
				}
			}

		}

	})

</script>

<div class="container" id="container">
	<div class="bg">
		<img class="bg-img" src="{$product.measure_image}" alt="bg">
	</div>
	<div class="example">
		<img class="hint-info" src="/Template/images/icon-hint.png" alt="">
		<span class="title">示例</span>
		<div class="example-detail">
			{$product.measure_description}
		</div>
	</div>
	<div class="edit-info">
		<img class="hint-info" src="/Template/images/icon-hint.png" alt="">
		<span class="title">编辑信息</span>
		<div class="edit-content">
			<foreach name="product.measure_json" item="vo">
				<div class="item"><span>{$vo.keyword}</span><input type="text" keyword="{$vo.code}" placeholder="请输入数据"></div>
			</foreach>
			<div class="line"></div>
		</div>
	</div>
	<div class="operation-btn">
		<div class="cancle-btn" v-on:click="cancel">取消</div>
		<div class="save-btn" v-on:click="save">保存</div>
	</div>
</div>
<include file="./Template/footer.html" />